const { merge } = require('webpack-merge')
const common = require('./webpack.common.js')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = merge(common, { 
    plugins: [
        new CleanWebpackPlugin(),
        new UglifyJsPlugin({
            parallel: true
        }),        
        new OptimizeCSSPlugin({
            cssProcessorOptions: { safe: true }
        }),
        new CopyWebpackPlugin({
            patterns: [
                {
                    from: 'public',
                }
            ],
        }),               
    ],
    optimization: {
        splitChunks: {
            chunks: 'all' //提取公共js、css到一个单独的bundle
        },
        concatenateModules: true,
        usedExports: true,
        minimize: true,
    }
})